package com.inns.position.hbase.config;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;

import java.io.IOException;

/**
 * Created by phoenix on 2018/4/6.
 */
@org.springframework.context.annotation.Configuration
@ConfigurationProperties(prefix = "hbase.zookeeper")
public class HBaseConfigurationBase {

    private Logger logger = LoggerFactory.getLogger(HBaseConfigurationBase.class);
    private String quorum;
    public static Connection connection;

    @Bean
    public Configuration configuration() {
        Configuration configuration = HBaseConfiguration.create();
        configuration.set("hbase.zookeeper.quorum", quorum);
//        configuration.set("zookeeper.znode.parent",znode);
//        configuration.set("hbase.master", HBaseMaster);
        logger.info("quorum is :" + quorum);
        return configuration;
    }

    @Bean
    public Connection connection() {
        Connection connection = null;
        try {
            connection = ConnectionFactory.createConnection(configuration());
            logger.info("获取connectiont连接成功！");
        } catch (IOException e) {
            e.printStackTrace();
            logger.error("获取connectiont连接失败！");
        }
        return connection;
    }

    public String getQuorum() {
        return quorum;
    }

    public void setQuorum(String quorum) {
        this.quorum = quorum;
    }
}
